/*
 * @lc app=leetcode.cn id=19 lang=javascript
 *
 * [19] 删除链表的倒数第 N 个结点
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} n
 * @return {ListNode}
 */
var removeNthFromEnd = function(head, n) {
   let l=new ListNode(null)
   l.next=head
   let fast=head
   let slow=l
   while(n>0){
       fast=fast.next
       n--
   }
   while(fast){
    fast=fast.next
    slow=slow.next
   }
   slow.next=slow.next.next
   return l.next
};
//虚假表头
//双指针（快慢）
//堆栈，或者遍历一遍求长度
// @lc code=end

